home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 47.7z / BS1 part 47 / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].7z / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].adf / piarc.lzh.parta / DHRZRDR.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-17  |  6KB  |  226 lines

  1. /*
  2.  * dhrzr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: February 27th, 1993
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.02
  9.  */
  10. parse arg '"' fullname '"'
  11. call pragma('stack',20000);
  12.  
  13. /*
  14.  * open rexxsupport.library -- needed for some functions
  15.  */
  16. if ~show('L',"rexxsupport.library") then do
  17.   if addlib('rexxsupport.library',0,-30,0) then do
  18.       /* everything's ok */
  19.     end;
  20.   else do
  21.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  22.     say 'Cannot operate dhrzr.rexx without this library - sorry!';
  23.     'finish';
  24.     exit 10;
  25.     end;
  26.   end;
  27.  
  28. /*
  29.  * This will automatically direct the script to the proper
  30.  * software, if it is running.
  31.  */
  32. prtnme = 'IP_Port'; /* assume Image Professional */
  33. if show('P','IP_Port') = 0 then do
  34.   if show('P','IM_Port') = 0 then do
  35.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  36.     say "This script requires IP, IM or IM F/c to run!";
  37.     exit(20);
  38.     end;
  39.   else do
  40.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  41.     end;                 /* We make em, user's break em.          */
  42.   end;
  43.  
  44.   /*
  45.    * This code attempts to read a file called "picmdpath" from REXX:
  46.    * If it can't find it, the script will assume that the commands
  47.    * associated with this PI Module are in "c:". If the file exists,
  48.    * the script will look in the path that is specified in the file.
  49.    * If you create this file, you MUST put a complete, correct path
  50.    * in it; if the commands are in a sub-directory, you have to put
  51.    * the trailing slash on the path (like, device:dir/).
  52.    * 
  53.    */
  54.   cmdpath = 'c:';
  55.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  56.     do
  57.       cmdpath = readln(fhandle);
  58.       call close(fhandle);  /* close the file    */
  59.     end
  60.  
  61. options;
  62. address;
  63.  
  64. if fullname = "" then do
  65.   prevpath = 'ram:'; /* put user in ram to start with... */
  66.  
  67.   if show('C',dhrzpath) = 1 then do
  68.     prevpath = getclip(dhrzpath);
  69.     end;
  70.  
  71.   address(prtnme);
  72.   options results;
  73.   'current';
  74.   bufdata = result; /* get name of buffer, if there is one */
  75.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  76.   if bname ~= '<none>' then do
  77.     bufname = bname;
  78.     end;
  79.   'filerequest "'||prevpath||'","'||bufname||'","","Load dhrz"';
  80.   dhrzfile = result;
  81.   options;
  82.  
  83.   if dhrzfile = 'FR_CANCELLED' then do
  84.     address(prtnme);
  85.     'imtofront';
  86.     'finish';
  87.     exit 0;
  88.     end;
  89.  
  90.   dhrzfile = expandfilename(dhrzfile);
  91.   thispath = gimmepath(dhrzfile);
  92.   call setclip(dhrzpath,thispath);
  93. end;
  94. else do
  95.   thispath = gimmepath(fullname);
  96.   call setclip(dhrzpath,gxpath);
  97.   dhrzfile = fullname;
  98. end;
  99.  
  100.   address command cmdpath||'DHRZRD c "'||dhrzfile||'"';
  101.   if rc ~= 0 then do
  102.     address(prtnme);
  103.     'message "Cannot read '||dhrzfile||' Error '||rc||'"';
  104.     'finish';
  105.     exit 0; /* this is not a proper dhrz file */
  106.     end;
  107.  
  108.   call open(fhandle,'ram:IP_LDDHRZ.tmp','read');      /* open the file */
  109.   rstring = readln(fhandle);
  110.   call close(fhandle);                     /* close the file    */
  111.   
  112.   address command 'c:delete >nil: ram:IP_LDDHRZ.tmp';
  113.   
  114.   parse var rstring width '/' height
  115.  
  116.   if height < 0 then do
  117.     'message "Bad Height: '||height||'"';
  118.     'finish';
  119.     exit 0;
  120.     end;
  121.  
  122.   if height > 32767 then do
  123.     'message "Bad Height: '||height||'"';
  124.     'finish';
  125.     exit 0;
  126.     end;
  127.  
  128.   if width < 0 then do
  129.     'message "Bad Width: '||width||'"';
  130.     'finish';
  131.     exit 0;
  132.     end;
  133.  
  134.   if width > 32767 then do
  135.     'message "Bad Width: '||width||'"';
  136.     'finish';
  137.     exit 0;
  138.     end;
  139.  
  140.   address(prtnme);
  141.   
  142.   'imtofront'; /* show user the IM screen */
  143.   /* New buffer is created at current resolution */
  144.   address(prtnme);
  145.   'autoredraw 0';
  146.   
  147.   options results;
  148.  
  149.   'newtargetted '||width||' '||height||' "'||gxname||'"'
  150.   if rc ~= 0 then do
  151.     'options';
  152.     "message Can't allocate buffer!";
  153.     'autoredraw 1';
  154.     'finish';
  155.     exit 0;
  156.     end
  157.   bnum = result;
  158.   
  159.   'backin '||bnum;
  160.   jackadr = result;
  161.   options;
  162.  
  163.   'imtofront';
  164.   'lockimage '||bnum;
  165.   address command cmdpath||'DHRZRD d'||jackadr||' "'||dhrzfile||'"';
  166.   'unlockimage '||bnum;
  167.  
  168.   address(prtnme);
  169.   'autoredraw 1';
  170.   'finish';
  171.   address;
  172.  
  173.   exit 0;
  174.  
  175. /*
  176.  * gimmepath
  177.  *
  178.  * This takes the provided argument and sucks the path out of it, then
  179.  * returns that path to the caller, sans file name.
  180.  */
  181. gimmepath:
  182.   arg fullnamegx;
  183.     tempgx = reverse(fullnamegx);
  184.     lengx = length(fullnamegx);   /* get length of string */
  185.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  186.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  187.     seploc = 0; /* assumes current dir, no path supplied */
  188.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  189.       seploc = (lengx - slashdex)+1;
  190.       end;
  191.     else do
  192.       if colondex ~= 0 then do /* we assume we are on a device */
  193.         seploc = (lengx - colondex)+1;
  194.         end;
  195.       end;
  196.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  197.   gxpath = left(fullnamegx,seploc);
  198.   return(gxpath);
  199.  
  200. /*
  201.  * Since this script can't be expected to know where the CD of the user
  202.  * is when this cmd is invoked, we have to check the path the user
  203.  * provides - if it's not specified right from a root, then we have
  204.  * to make it a complete specification from the root.
  205.  */
  206. expandfilename:
  207.   parse arg jfile;
  208.   if index(jfile,':') = 0 then do
  209.     curdir = pragma(D);
  210.     if right(curdir,1) ~= ':' then do
  211.       if right(curdir,1) ~= '/' then do
  212.         if curdir ~= '' then do
  213.           curdir = curdir || '/';
  214.           end;
  215.         end;
  216.       end;
  217.     jfile = curdir||jfile;
  218.     end;
  219.   return(jfile);
  220.  
  221. rvalue:
  222.   wordnum = c2d(readch(fhandle,1)) * 256;
  223.   wordnum = wordnum + c2d(readch(fhandle,1));
  224.   return wordnum;
  225.  
  226.